/*
 * author: Andriamananony, Meß, Falk
 */

package auftrag;

import util.Interval;


public class Operation implements Comparable<Operation> {
	private Ressource mRessource;
	private int intDuration;
	private int intStep;
	private Variante varParent;
	private Interval ivPlanned = null;
	
	//Vorangehende Operation
	private Operation prevOp;

	public Operation (Variante v, int intStep, Ressource r, int d) {
		this(v, intStep, r, d, null);
	}
	
	public Operation (Variante v, int intStep, Ressource r, int d, Operation pOp){
		prevOp = pOp;
		this.intStep = intStep;
		this.varParent = v;
		v.addOperation(this);
		intDuration = d;
		mRessource = r;
	}
	
	public void setIntervall(Interval i){
		ivPlanned = i;
	}
	
	public Interval getInterval(){
		return ivPlanned;
	}
	
	/*
	 * Gibt die vorangehende Operation zurück. Damit kann schon bei der Planung die richte Reihenfolge garantiert werden.
	 */
	public Operation getPreviousOperation(){
		return prevOp;
	}
	
	public void setPreviousOperation(Operation o){
		prevOp = o;
	}

	public Ressource getRessource() {
		return this.mRessource;
	}
	
	public int getDuration(){
		return intDuration;
	}
	
	public Variante getParent(){
		return varParent;
	}
	
	public int getStep(){
		return intStep;
	}
	
	@Override
	public String toString(){
		return(getParent().getParent()+"_"+getParent()+"_O"+intStep);
	}

	@Override
	public int compareTo(Operation o) {
		if(intStep < o.intStep)
			return -1;
		else if (intStep == o.intStep)
			return 0;
		return 1;
	}
}
